<?php
/*
	[gunianwang system]
	NAME:footer_control 姑娘网尾部footer管理
	AUTHOR:sql
	DATE:2012-07-19
*/

if (!defined('IN_ELS'))
{
    die('Hacking attempt');
}
class control extends footerbase {
	var $pagecount 		= 0;
	var $currendnum 	= 1;
	var $pageSize 		= 50;	//每页多少条
	var $pageNumSize 	= 10;	//分页数
	
	function control() {
		$this->footerbase();
		if(!empty($_REQUEST['currendnum'])){
			$this->currendnum=$_REQUEST['currendnum'];
		}
		$act=empty($_REQUEST['a']) ? 'empty' : $_REQUEST['a'];
		
		if($act=="empty")				$this->footerList();//footer底部列表
		if($act=="footerdel")			$this->footerdel();// footer删除
		if($act=="footer_insert")		$this->footer_insert();// 添加底部类别
		if($act=="footer_save")			$this->footer_save();//保存分类
		if($act=="up_is_ok")			$this->footer_up_is_ok();//修改显示状态
		
		
	}  
	function footerList()                //主页显示
	{
		// news List
		
		$where = "where 1=1 ";
		$url = "";
		$dataCount=$this->getCount($where);
		$startNum = $this->pageSize*($this->currendnum-1);
		$limitText = " limit ".$startNum." , ".$this->pageSize;
		$pagecountdata=array();
		require_once ELS_ROOT.'lib/paging.class.php';
		$pg =  new paging();
		$pg -> setLinkText("<a href='admin.php?p=footer$url&currendnum=!!PageNum!!'>!!LinkText!!</a>");
		$pg -> setCurrendnum(  $this-> currendnum);
		$pg -> setPageSize(    $this-> pageSize);
		$pg -> setPageNumSize( $this-> pageNumSize);
		$pg -> setDataCount(   $dataCount);
		$pagecountdata = $pg ->makePageText();
		
		$one = $this->getone();// 获取一级
		$this->view->assign('one',$one);
		$list=$this->getList($where,$limitText);
		$this->view->assign('list',$list);
		$this->view->assign('pagecount' ,$pagecountdata);
		$this->view->assign('currendnum',$currendnum);
		$this->view->assign('user_leve',$search_1);
		$this->view->display('footer_list');

	}

	// 删除单个footer
	function footerdel(){
		$id = empty($_REQUEST['id'])?"":$_REQUEST['id'];
		if($id!='')
		{
			$sql_parent_id = $this->db->result_first("select parent_id from gnw_footer where id='$id' limit 1");
			//echo $sql_parent_id;exit;
			if($sql_parent_id==0)
			{
				$this->db->query("DELETE FROM gnw_footer WHERE parent_id = '$id'");// 如果是一级分类 连同删除本级的2级分类
			}
			
			$this->db->query("DELETE FROM gnw_footer WHERE id = '$id' limit 1");
			
			echo "<script>alert('删除成功！');</script>";
			$this->pageRedirect("?p=footer");
		}
		
	}
	//添加底部类别footer页面
	function footer_insert()
	{
		$ones = $this->getone();// 获取一级
		//print_r($ones);exit;
		$this->view->assign('one',$ones);
		$this->view->display('footer_insert');
	}
	//保存footer分类
	function footer_save()
	{
		//print_r($_REQUEST);exit;
		if($_REQUEST['types']=='sec'){
			$res = $this->db->query("insert into gnw_footer(`parent_id`,`name`,`url`,`is_ok`) values('".$_REQUEST['parent_id']."','".$_REQUEST['name']."','".$_REQUEST['url']."',".$_REQUEST['is_ok'].")");
			if($res)
			{
				echo "<script>alert('添加成功！');</script>";
				$this->pageRedirect("?p=footer");
			}
			else{
				echo "<script>alert('添加失败！');</script>";
			}
		}
		elseif($_REQUEST['types']=='stair')
		{
			$ress = $this->db->query("insert into gnw_footer(`parent_id`,`name`,`url`,`is_ok`) values(0,'".$_REQUEST['stair_name']."','".$_REQUEST['stair_url']."',".$_REQUEST['stair_is_ok'].")");
			if($ress)
			{
				echo "<script>alert('添加成功！');</script>";
				$this->pageRedirect("?p=footer");
			}
			else{
				echo "<script>alert('添加失败！');</script>";
			}
		}
	}
	function maildelAll()
	{
		$mail_id= empty($_POST['ids'])?array():$_POST['ids'];
		//print_r($mail_id);exit;
		//删除
		if($mail_id){
			for($i=0;$i<count($mail_id);$i++){
				
				$this->db->query("DELETE FROM gnw_in_mail WHERE id = '$mail_id[$i]'");
			}
			echo "<script>alert('批量删除成功！');</script>";
		}
		
		$this->pageRedirect("?p=in_mail&a=list");
	}
	//修改是否显示
	function footer_up_is_ok()
	{
		$id = $_REQUEST['id'];
		$where = " id=$id ";
		$sql="select is_ok from gnw_footer where id=$id limit 1";
		$is_ok =$this->db->result_first($sql);
		
		if($is_ok==1 && $id!='')
		{
			$data_arr['is_ok']=2;
		}
		else if($is_ok==2 && $id!='')
		{
			$data_arr['is_ok']=1;
		}
		$this->update_is_ok($data_arr,$where);
		echo $data_arr['is_ok'];
	}


}
?>